package com.crm.controller;


import com.crm.annotation.Audit;
import com.crm.annotation.CurrentUser;
import com.crm.annotation.LoginRequired;
import com.crm.annotation.WebLog;
import com.crm.model.User;
import com.crm.model.dto.PaperDTO;
import com.crm.model.dto.UserDTO;
import com.crm.service.IUserService;
import com.crm.uilt.DataView;
import com.crm.uilt.Moudle;
import com.crm.uilt.RestResult;
import com.crm.uilt.reflect.LoginValueReturn;
import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotNull;
import javax.xml.crypto.Data;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zjd
 * @since 2021-04-01
 */
//@ApiIgnore
@RestController
@RequestMapping("/user")
@Validated
public class UserController {

    @Autowired
    private IUserService userService;
    @PostMapping("/getUser")
    public User getUser(){
        return userService.getById(1);
    }

    @PostMapping("/addUser")
    public boolean addUser(){
        List<User> userList=new ArrayList<>();
        for (int i=0; i<10 ;i++ ) {
            User user=new User();
            user.setId((long) i);
            user.setName("name="+i);
            user.setPhone("123416");
            userList.add(user);

        }
        return  userService.saveBatch(userList);
    }

    @JsonView(DataView.Basic.class)
    @GetMapping("/listBasic")
    public List<UserDTO> listBasic(){
        List<UserDTO> allUser = userService.findAllUser();
        return allUser;
    }

    @JsonView(DataView.Company.Login.class)
    @GetMapping("/listLogin")
    public List<UserDTO> listLogin(){
        List<UserDTO> allUser = userService.findAllUser();
        return allUser;
    }


    @JsonView(DataView.Company.Default.class)
    @GetMapping("/listDefault")
    public List<UserDTO> listDefault(){
        List<UserDTO> allUser = userService.findAllUser();
        return allUser;
    }

    @GetMapping("/input")
    public void input(@RequestParam("data") Date data,@RequestParam("str") String str){


    }

    @GetMapping("/notInput")
    public void notInput(@NotNull(message = "请传入参数") String id){


    }
    @PostMapping("/bind")
    @Audit(moudleCode = Moudle.LOGIN, extension = LoginValueReturn.class)
    public RestResult bind(@Validated String id){
        RestResult r= new RestResult();
        r.setCode(HttpStatus.OK.value());
        return r;
    }
    //发布指定试卷
    @PostMapping("publishPaper")
    @WebLog()
    public Boolean doPublishPaper(@RequestBody @Validated PaperDTO request) {
        //处理传入试卷id
        return true;
    }

    @LoginRequired
    @PostMapping("sss")
    public Boolean ssss(@CurrentUser User user) {
        //处理传入试卷id
        System.out.println(user.getId() + "/"+user.getName());
        return true;
    }

}
